package test.socket.simplesocket;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class IOService {

    public static  ServerSocket serverSocket = null;

    static {
        try {
            serverSocket = new ServerSocket(8888);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args){

        new Thread(()->{
            while (true) {
                try {
                    Socket socket = serverSocket.accept();
                    new Thread(()->{
                        byte[] info = new byte[1024];
                        while(true) {
                            int length;
                            try {
                                if ((length = socket.getInputStream().read(info)) != -1) {
                                    System.out.println(new String(info,0,length));
                                }
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    }).start();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }).start();
    }


}
